# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

# 导入appium的webdriver模块
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
# 导入time模块的sleep函数
from time import sleep
"""
在执行这个用例之前，你要确保：
1、你的设备是开启的状态
2、你是用adb连接了设备才可以

"""

caps = {}
# 设置app的包名
caps["appPackage"] = "com.jiahui.health.app"
# 设置app的启动Activity
caps["appActivity"] = ".ui.SplashActivity"
# 设置设备系统版本
caps["platformVersion"] = "7.1.2"
# 设置设备系统名称
caps["platformName"] = "Android"
# 设置设备名
caps["deviceName"] = "dream2lteks"

# 创建一个远程的webdriver，参数为caps
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(15)

# 查找同意按钮
el1 = driver.find_element(MobileBy.ID,"com.jiahui.health.app:id/tv_agree")
el1.click()
sleep(2)
# 点击设置外出按钮
el2 = driver.find_element(MobileBy.ID,"com.jiahui.health.app:id/setOutButton")
el2.click()
sleep(2)
# 点击取消按钮
el3 = driver.find_element(MobileBy.ID,"com.jiahui.health.app:id/if_close")
el3.click()
sleep(2)
# 定义一个函数，用于点击屏幕上的某个位置
TouchAction(driver).tap(x=110, y=559).perform() #点击健康记录
el4 = driver.find_element(MobileBy.ID,"com.jiahui.health.app:id/et_mobile") #输入手机号
el4.send_keys("13940114587")
sleep(2)
el5 = driver.find_element(MobileBy.ID,"com.jiahui.health.app:id/accb_policy") #点击用户须知
el5.click()
sleep(2)
el6 = driver.find_element(MobileBy.ID,"com.jiahui.health.app:id/btn_login") #验证码
el6.click()
